package com.jqb.struts2lab01.action;

import com.jqb.struts2lab01.beans.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	
	private User user;

	public String execute() {
		System.out.println("execute");
		ActionContext.getContext().put("msg", "welcome:"+user.getUsername());
		return SUCCESS;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Override
	public void validate() {
		System.out.println("validate");
		if (user != null) {
			if (!user.getPassword().matches(("^\\S{6,8}$"))) {
				this.addFieldError(user.getPassword(), "密码必须为6-8位");
			}
		}
	}
}
